home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / Preinstalled MacPerl (FAT) / t / lib / gdbm.t < prev    next >
Encoding:
Text File  |  1995-10-30  |  2.5 KB  |  125 lines  |  [TEXT/McPL]

  1. #!./perl
  2.  
  3. # $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $
  4.  
  5. # We don't have gdbm
  6.  
  7. print "1..0\n";
  8. exit 0;
  9.  
  10. __END__
  11.  
  12. BEGIN {
  13.     @INC = '../lib';
  14.     require Config; import Config;
  15.     if ($Config{'extensions'} !~ /\bGDBM_File\b/) {
  16.     print "1..0\n";
  17.     exit 0;
  18.     }
  19. }
  20.  
  21. use GDBM_File;
  22.  
  23. print "1..12\n";
  24.  
  25. unlink <Op.dbmx*>;
  26.  
  27. umask(0);
  28. print (tie(%h,GDBM_File,'Op.dbmx', &GDBM_WRCREAT, 0640) ? "ok 1\n" : "not ok 1\n");
  29.  
  30. $Dfile = "Op.dbmx.pag";
  31. if (! -e $Dfile) {
  32.     ($Dfile) = <Op.dbmx*>;
  33. }
  34. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
  35.    $blksize,$blocks) = stat($Dfile);
  36. print (($mode & 0777) == 0640 ? "ok 2\n" : "not ok 2\n");
  37. while (($key,$value) = each(%h)) {
  38.     $i++;
  39. }
  40. print (!$i ? "ok 3\n" : "not ok 3\n");
  41.  
  42. $h{'goner1'} = 'snork';
  43.  
  44. $h{'abc'} = 'ABC';
  45. $h{'def'} = 'DEF';
  46. $h{'jkl','mno'} = "JKL\034MNO";
  47. $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
  48. $h{'a'} = 'A';
  49. $h{'b'} = 'B';
  50. $h{'c'} = 'C';
  51. $h{'d'} = 'D';
  52. $h{'e'} = 'E';
  53. $h{'f'} = 'F';
  54. $h{'g'} = 'G';
  55. $h{'h'} = 'H';
  56. $h{'i'} = 'I';
  57.  
  58. $h{'goner2'} = 'snork';
  59. delete $h{'goner2'};
  60.  
  61. untie(%h);
  62. print (tie(%h,GDBM_File,'Op.dbmx', &GDBM_WRCREAT, 0640) ? "ok 4\n" : "not ok 4\n");
  63.  
  64. $h{'j'} = 'J';
  65. $h{'k'} = 'K';
  66. $h{'l'} = 'L';
  67. $h{'m'} = 'M';
  68. $h{'n'} = 'N';
  69. $h{'o'} = 'O';
  70. $h{'p'} = 'P';
  71. $h{'q'} = 'Q';
  72. $h{'r'} = 'R';
  73. $h{'s'} = 'S';
  74. $h{'t'} = 'T';
  75. $h{'u'} = 'U';
  76. $h{'v'} = 'V';
  77. $h{'w'} = 'W';
  78. $h{'x'} = 'X';
  79. $h{'y'} = 'Y';
  80. $h{'z'} = 'Z';
  81.  
  82. $h{'goner3'} = 'snork';
  83.  
  84. delete $h{'goner1'};
  85. delete $h{'goner3'};
  86.  
  87. @keys = keys(%h);
  88. @values = values(%h);
  89.  
  90. if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";}
  91.  
  92. while (($key,$value) = each(h)) {
  93.     if ($key eq $keys[$i] && $value eq $values[$i] && $key gt $value) {
  94.     $key =~ y/a-z/A-Z/;
  95.     $i++ if $key eq $value;
  96.     }
  97. }
  98.  
  99. if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";}
  100.  
  101. @keys = ('blurfl', keys(h), 'dyick');
  102. if ($#keys == 31) {print "ok 7\n";} else {print "not ok 7\n";}
  103.  
  104. $h{'foo'} = '';
  105. $h{''} = 'bar';
  106.  
  107. # check cache overflow and numeric keys and contents
  108. $ok = 1;
  109. for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
  110. for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
  111. print ($ok ? "ok 8\n" : "not ok 8\n");
  112.  
  113. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
  114.    $blksize,$blocks) = stat($Dfile);
  115. print ($size > 0 ? "ok 9\n" : "not ok 9\n");
  116.  
  117. @h{0..200} = 200..400;
  118. @foo = @h{0..200};
  119. print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n";
  120.  
  121. print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n");
  122. print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n");
  123.  
  124. unlink 'Op.dbmx.dir', $Dfile;
  125.